<template>
    <el-dialog
            :title="!dataForm.assessmentId ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="培训效果评估ID，主键" prop="assessmentId">
                        <el-input v-model.number="dataForm.assessmentId" placeholder="培训效果评估ID，主键"></el-input>
                </el-form-item>
                <el-form-item label="培训记录ID，对应培训记录表" prop="trainingId">
                        <el-input v-model.number="dataForm.trainingId" placeholder="培训记录ID，对应培训记录表"></el-input>
                </el-form-item>
                <el-form-item label="评估方式" prop="assessmentMethod">
                        <el-input v-model="dataForm.assessmentMethod" placeholder="评估方式"></el-input>
                </el-form-item>
                <el-form-item label="评估得分" prop="assessmentScore">
                        <el-input v-model.number="dataForm.assessmentScore" placeholder="评估得分"></el-input>
                </el-form-item>
                <el-form-item label="评估结果描述" prop="assessmentResult">
                        <el-input v-model="dataForm.assessmentResult" placeholder="评估结果描述"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            assessmentId: null,
            trainingId: null,
            assessmentMethod: null,
            assessmentScore: null,
            assessmentResult: null
          },
          dataRule: {
            assessmentId: [
                        { required: true, message: '培训效果评估ID，主键不能为空', trigger: 'blur' }
            ],
            trainingId: [
                        { required: true, message: '培训记录ID，对应培训记录表不能为空', trigger: 'blur' }
            ],
            assessmentMethod: [
                        { required: true, message: '评估方式不能为空', trigger: 'blur' }
            ],
            assessmentScore: [
                        { required: true, message: '评估得分不能为空', trigger: 'blur' }
            ],
            assessmentResult: [
                        { required: true, message: '评估结果描述不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.assessmentId = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.assessmentId = id || 0
            if (this.dataForm.assessmentId) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_training_assessment/info/${this.dataForm.assessmentId}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appaudittrainingassessment
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/audit_training_assessment/${!this.dataForm.assessmentId ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>